<?php
	// First generate here with defaults: http://spritegen.website-performance.org/
	// Then run this script on generated css

	error_reporting(E_ALL);
	ini_set('display_errors', true);

	$type	= basename($_GET['type']);
	$file	= basename($_GET['file']);
	$icons	= file("$type/$file.css");

	foreach ($icons as $icon) {
		$icon = str_replace('.sprite-', "@mixin icon-$type-", $icon);
		$icon = str_replace('{ background', "{ @include icon-$type; background", $icon);
		$icon = str_replace('; }', '; } }', $icon);
		$icon = str_replace('{', ' ($where: before) { &:#{$where} {', $icon);
		$icon = preg_replace('/width: .*?px; height: .*?px; /', '', $icon);
		$icon = preg_replace(
			'/position: (.*?) (.*?);/', 
			'position: (((($icon-bg-size - $icon-size) / 2) + \1) ((($icon-bg-size - $icon-size) / 2) + \2));', 
			$icon
		);

		echo "$icon<br/>";
	}
?>
